<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : ProductsXslTransform.xsl
    Created on : May 7, 2015, 12:11 AM
    Author     : Khaled Daham
    Description:
        Transform between output from GUPS/GUTi products
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">

    <xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes" indent="yes"/>

    <xsl:template match="TABLE">
        <catalogue>
            <sourceSystemHSAId>
                <root>1.2.752.129.2.1.4.1</root>
                <!-- OID för HSA -->
                <extension>SE2321000016-9D6N</extension>
                <!-- HSA-id för GUPS -->
            </sourceSystemHSAId>
            <county>
                <root>1.2.752.129.2.2.1.18</root>
                <!-- OID för SCB landsting -->
                <extension>01</extension>
                <!-- 01 för Stockholm Läns Landsting -->
            </county>

            <xsl:for-each select="PRODUCTS">
                <product>
                    <name>
                        <xsl:value-of select="Namn"/>
                    </name>
                    <productId>
                        <xsl:value-of select="UUID"/>
                    </productId>
                    <description>
                        <xsl:value-of select="Beskrivning"/>
                    </description>
                    <!-- check if element exists and not empty -->
                    <xsl:if test="Uppdragid and not(Uppdragid = '')">
                        <property>
                            <codeSystem>UPPDRAGID_OID</codeSystem>
                            <code>
                                <xsl:value-of select="Uppdragid"/>
                            </code>
                        </property>
                    </xsl:if>
                    <!-- check if element exists and not empty -->
                    <xsl:if test="ID_hsa_x_snomed and not(ID_hsa_x_snomed = '')">
                        <property>
                            <codeSystem>1.2.752.129.2.1.4.1</codeSystem>
                            <code>
                                <xsl:value-of select="ID_hsa_x_snomed"/>
                            </code>
                        </property>
                    </xsl:if>
                </product>
            </xsl:for-each>
        </catalogue>
    </xsl:template>

</xsl:stylesheet>
